var express = require('express');
var router = express.Router();
var eventEmitter=require('events');
const { EventEmitter } = require('stream');
const myEmitter=new EventEmitter()

var response_data = {
    'code': 0,
    'message': 'success',
    'version': '1.0.0'
  }

router.get("/",function(req,res) {
    const json={
        code:200,
        message:"成功",
        data:{
            name:"张三",
            schoole:"清华大学"
        }
    }
    res.send({
        ...response_data,
        ...json
    })
})

router.get("/world",function(req,res){
    res.sendfile('./views/hello.html')
})

router.get("/event",function(req,res){
    myEmitter.on('event',()=>{
        console.log("A")
    })

    myEmitter.addListener('click',()=>{
        console.log("super man!")
    })

    myEmitter.emit("event")
    myEmitter.emit("click")
})

router.post("/",function(req,res){
    res.send('got a post request')
})

router.put("/",function(req,res){
    res.send("got a put request at /user")
})

router.delete("/user",function(req,res){
    res.send("got a delete request")
})

module.exports = router;
